package com.canbot.u05.activity.agenda.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.RelativeLayout
import butterknife.ButterKnife
import com.canbot.u05.R
import kotlinx.android.synthetic.main.activity_agenda_create_work_type_item.view.*

/**
 * @author yinxiaowei
 * @date 2019/5/31
 */
class AgendaItemChoiceView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = -1) : RelativeLayout(context, attrs, defStyleAttr) {
    init {
        initView()
        initStyle(context, attrs)
    }

    private fun initStyle(context: Context, attrs: AttributeSet?) {
        val typedArray = context.obtainStyledAttributes(attrs, R.styleable.AgendaItemChoiceView)
        val resourceId = typedArray.getResourceId(R.styleable.AgendaItemChoiceView_itemContent, -1)
        type_name.text = context.getString(resourceId)
        typedArray.recycle()
    }

    private fun initView() {
        val view = LayoutInflater.from(context).inflate(R.layout.activity_agenda_create_work_type_item, this)
        ButterKnife.bind(this, view)
    }

    override fun setSelected(selected: Boolean) {
        super.setSelected(selected)
        if (selected) {
            btn_isSeletor.visibility = View.VISIBLE
        } else {
            btn_isSeletor.visibility = View.INVISIBLE
        }
    }
}
